from tornado_request_mapping import request_mapping

from common.base_handler import BasicHandler
from common.decorator import login_required
from schemas.leetcode_question_schema import LeetCodeQuestionSchema, UpdateQuestionSchema, \
    DeleteQuestionSchema
from services.leetcode_question_service import LeetCodeQuestionService


@request_mapping("/leet_code_note")
class LeetCodeNoteHandler(BasicHandler):

    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)
        self.service = LeetCodeQuestionService()

    @request_mapping("/list_question", 'get', '获取所有题目')
    @login_required()
    async def list_question(self):
        response = await self.service.list_question()
        return self.send_response(response.code, response.data, response.msg)

    @request_mapping("/create_question", 'post', '创建题目')
    @login_required()
    async def create_question(self):
        data = self.data
        params = self.check_params(LeetCodeQuestionSchema, **data)
        response = await self.service.create_question(params)
        return self.send_response(response.code, response.data, response.msg)

    @request_mapping("/update_question", 'put', '修改/答题')
    @login_required()
    async def update_question(self):
        data = self.data
        params = self.check_params(UpdateQuestionSchema, **data)
        response = await self.service.update_question(params)
        return self.send_response(response.code, response.data, response.msg)

    @request_mapping("/delete_question", 'delete', '删除')
    @login_required()
    async def delete_question(self):
        data = self.data
        params = self.check_params(DeleteQuestionSchema, **data)
        response = await self.service.delete_question(params)
        return self.send_response(response.code, response.data, response.msg)
